# -*- coding: utf-8 -*-
'''
@文件    :config.py
@说明    :
@时间    :2025/09/04 00:35:56
@作者    :浪晋
@版本    :1.0
'''
import os
from typing import Dict, Union

class Config:
    DEBUG = False
    SECRET_KEY = "cd2e4fc86aa568e7d735a7c8235607ff"    # SESSION配置

    # ================================================= #
    # ******************** MySql配置 ******************* #
    # ================================================= #
    MYSQL_HOST: str = "loaclhost"
    MYSQL_PORT: int = 3306
    MYSQL_DB_NAME: str = "grapefruit"
    MYSQL_USER: str = "root"
    MYSQL_PASSWORD: str = "123456"

    # ================================================= #
    # ******************** Redis配置 ******************* #
    # ================================================= #
    REDIS_HOST: str = "loaclhost"
    REDIS_PORT: int = 6379
    REDIS_DB_NAME: int = 0
    REDIS_USER: str = "default"
    REDIS_PASSWORD: str = "123456"
    REDIS_PREFIX_NAME: str = "lemon"         # redis前缀名

    @property
    def MYSQL_CONFIG(self) -> Dict[str, Union[str, bool, None]]:
        """获取MYSQL的连接配置"""
        return {
            "host": self.MYSQL_HOST,
            "port": self.MYSQL_PORT,
            "db": self.MYSQL_DB_NAME,
            "username": self.MYSQL_USER,
            "password": self.MYSQL_PASSWORD
        }

    @property
    def REDIS_CONFIG(self) -> str:
        """获取REDIS的连接配置"""
        return {
            "host": self.REDIS_HOST,
            "port": self.REDIS_PORT,
            "db": self.REDIS_DB_NAME,
            "username": self.REDIS_USER,
            "password": self.REDIS_PASSWORD
        }
    

class ProductionConfig(Config):
    DEBUG = False

class DevelopmentConfig(Config):
    DEBUG = True

class TestingConfig(Config):
    DEBUG = True


def get_config() -> Config:
    env = os.getenv("FLASK_ENV", default="dev").lower()
    if env == "prod":
        return ProductionConfig()
    elif env == "test":
        return TestingConfig()
    else:
        return DevelopmentConfig()


config = get_config()